# server (daemon) entry point

from ptcDaemon import pkg_info
from ptcDaemon.server import *

import os, sys
import argparse


def main(argv = sys.argv):
    prog_name = os.path.basename(argv[0])
    parser = prepare_option(prog_name)
    args = parser.parse_args(argv[1:])

    if args.version:
        info = pkg_info()
        print info.project_name, info.version
        return 0

    # process command-line arguments

    # main process loop
    server = PTCServer()
    server.serve()

    return 0


def prepare_option(prog):
    parser = argparse.ArgumentParser(description = 'Splits and tracks group payments')

    # optional arguments
    parser.add_argument(
        '-v', '--version',
        action = 'store_true',
        default = False,
        help = 'display the version information',
        dest = 'version'
        )

    return parser


# entry point
if __name__ == '__main__':
    main()
